package com.googlecode.bip.xml.export;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;

/**
 * TODO: doc
 *
 * @author Claude CHOISNET
 */
// not public
class XMLQuestion
        implements XMLAppender
{
    private List<XMLQuestionLocal> questionlocalList;
    private int idquestion;
    private int order;
    private int isactive;
    private int minvalue;
    private int maxvalue;
    private int defaultvalue;

    /**
     * TODO: doc
     *
     * @param idquestion
     * @param order
     * @param isactive
     * @param minvalue
     * @param maxvalue
     * @param defaultvalue
     * @throws NamingException
     * @throws SQLException
     */
    public XMLQuestion(
            XMLSurveyConnection connection,
            int                 idquestion,
            int                 order,
            int                 isactive,
            int                 minvalue,
            int                 maxvalue,
            int                 defaultvalue
            )
        throws SQLException, NamingException
    {
        this.idquestion = idquestion;
        this.order = order;
        this.isactive = isactive;
        this.minvalue = minvalue;
        this.maxvalue = maxvalue;
        this.defaultvalue = defaultvalue;

        this.questionlocalList = XMLQuestionLocalFactory.createList( connection, this );
    }

    /**
     * <XMP>
     * <!ELEMENT question      (questionlocal+,idquestion,order,isactive,minvalue,maxvalue,defaultvalue)>
     * <!ELEMENT idquestion    (#PCDATA)>
     * <!ELEMENT minvalue      (#PCDATA)>
     * <!ELEMENT maxvalue      (#PCDATA)>
     * <!ELEMENT defaultvalue  (#PCDATA)>
     * </XMP>
     */
    @Override
    public void appendXML( Appendable a ) throws IOException
    {
        a.append( "<question><!-- (idquestion=" )
         .append( Integer.toString( idquestion ) )
         .append( ") -->\n" );

        XMLAppenderHelper.appendXML( a, questionlocalList );

        XMLAppenderHelper.appendXMLValue( a, "idquestion", idquestion );
        XMLAppenderHelper.appendXMLValue( a, "order", order );
        XMLAppenderHelper.appendXMLValue( a, "isactive", isactive );
        XMLAppenderHelper.appendXMLValue( a, "minvalue", minvalue );
        XMLAppenderHelper.appendXMLValue( a, "maxvalue", maxvalue );
        XMLAppenderHelper.appendXMLValue( a, "defaultvalue", defaultvalue );

        a.append( "</question><!-- (idquestion=" )
         .append( Integer.toString( idquestion ) )
         .append( ") -->\n" );
    }

    /**
     * Returns the idquestion
     * @return the idquestion
     */
    public int getIdQuestion()
    {
        return idquestion;
    }

}
